<template>
	<view class="homepage p30">
		<view class="card p20">
			<view class="userInfo dis">
				<view class="userImg">
					<image v-if="!userInfo" src="/post/static/default_avatar.jpg" mode=""></image>
					<image v-else :src="userInfo?.user?.avatar" mode="aspectFill"></image>
				</view>
				<view class="userIn dis">
					<view class="userName">{{ userInfo?.user?.nickname }}</view>
					<view class="userId">账号ID：{{ userInfo?.user?.id }}</view>
				</view>
			</view>
			<view class="userData">
				<view class="dataItem pt20 dis">
					<view class="lable">身份:</view>
					<view class="value">{{ haveData.userType }}</view>
				</view>
				<view class="dataItem pt20 dis">
					<view class="lable">真实姓名:</view>
					<view class="value">{{ haveData.realName }}</view>
				</view>
				<view class="dataItem pt20 dis">
					<view class="lable">性别:</view>
					<view class="value">{{ haveData.sex == 0 ? '男' : haveData.sex == 1 ? '女' : '未知' }}</view>
				</view>
				<view class="dataItem pt20 dis">
					<view class="lable">手机号:</view>
					<view class="value">{{ haveData.phone }}</view>
				</view>
				<view class="dataItem pt20 dis">
					<view class="lable">入学年份:</view>
					<view class="value">{{ haveData.enrollmentYear }}</view>
				</view>
				<view class="dataItem pt20 dis">
					<view class="lable">宿舍楼:</view>
					<view class="value">{{ haveData.dormitory }}</view>
				</view>
				<view class="dataItem pt20 dis">
					<view class="lable">学校:</view>
					<view class="value">{{ haveData.departmentName }}</view>
				</view>
				<view class="dataItem pt20 dis">
					<view class="lable">班级:</view>
					<view class="value">{{ haveData.classTitle }}</view>
				</view>
				<view class="dataItem pt20 dis">
					<view class="lable">专业/学院:</view>
					<view class="value">{{ haveData.major }}</view>
				</view>
			</view>
			<view class="butList dis">
				<view class="butItem primaryBut" @click="setUser">修改信息</view>
				<view class="butItem errBut" @click="openModal(2)">注销</view>
				<view class="butItem primaryBut">取消认证</view>
			</view>
		</view>
	</view>
	<up-modal :title="title" :show="show10" :showCancelButton="true" @cancel="cancelFun" @confirm="confirmTextFun">
		<up-input :placeholder="placeholder" border="surround" v-model="value"></up-input>
	</up-modal>
</template>

<script setup>
import { getUserInfo, identityAxios, logoff } from '@/config/api.js';
import { ref } from 'vue';
import { onShow, onLoad, onReachBottom, onPageScroll } from '@dcloudio/uni-app';
onLoad((options) => {
	getUserInfoFun();
});

onShow(() => {});

// 账号设置
const setUser = () => {
	uni.navigateTo({
		url: '/post/user/index'
	});
};

// 弹窗
const title = ref('修改昵称');
const placeholder = ref('请输入要修改的昵称');
const openModal = (val) => {
	if (val == 1) {
		title.value = '修改昵称';
		placeholder.value = '请输入要修改的昵称';
	} else {
		title.value = '确定要注销吗？';
		placeholder.value = '请填写立即注销';
	}
	show10.value = true;
};
const show10 = ref(false);
const value = ref('');
const cancelFun = () => {
	show10.value = false;
	value.value = '';
};
const confirmTextFun = async () => {
	if (title.value == '修改昵称') {
	} else {
		if (value.value != '立即注销') {
			uni.showToast({
				title: '请输入立即注销',
				icon: 'none'
			});
		} else {
			const res = await logoff();
			console.log(res);
			if (res.code == 0) {
				uni.showToast({
					title: '您的账号已注销',
					icon: 'none'
				});
			} else {
				uni.showToast({
					title: res.message,
					icon: 'none'
				});
			}
		}
	}
	cancelFun();
};

// 用户信息
const userInfo = ref({});
const isApprove = ref('');
const isAdmin = ref('');
const isMaster = ref('');
const sysWidth = ref('width: 0%;');
const getUserInfoFun = async () => {
	const res = await getUserInfo();
	// console.log(res);
	if (res.code == 0) {
		identityAxiosFun();
		// console.log(res.data);
		userInfo.value = res.data;
	}
};

const haveData = ref({});
// 获取身份认证信息
const identityAxiosFun = async () => {
	const res = await identityAxios();
	console.log(res.data);
	if (res.code == 0) {
		haveData.value = res.data.userIdentity;
	}
};
</script>

<style lang="scss" scoped>
.homepage {
	width: 100%;
	.card {
		background: #fff;
		border-radius: 20rpx;
	}
	.userInfo {
		justify-content: space-between;
		align-items: center;
		width: 100%;
		font-size: 28rpx;
		.userImg {
			margin-right: 20rpx;
			width: 100rpx;
			height: 100rpx;
			background: #f2f2f2;
			border-radius: 50%;
			overflow: hidden;
		}
		.userIn {
			flex: 1;
			flex-direction: column;
			justify-content: space-between;
			// align-items: center;
			.userId {
				font-size: 24rpx;
				color: #a7a8bc;
			}
		}
	}
	.userData {
		font-size: 26rpx;
		.dataItem {
			line-height: 75rpx;
			.lable {
				margin-right: 15rpx;
				width: 200rpx;
				// background-color: #a7a8bc;
				text-align: center;
			}
		}
	}
	.butList {
		justify-content: space-around;
		.butItem {
			width: 200rpx;
			line-height: 75rpx;
			text-align: center;
			border-radius: 15rpx;
			font-size: 26rpx;
			color: #fff;
		}
	}
}
</style>
<style>
page {
	background-color: #f2f2f2;
}
.pt20 {
	padding-top: 20rpx;
}
</style>
